package ThreadSafety;

public class DeadLocker {
    public static void main(String[] args) {
        Object A = new Object();
        Object B = new Object();
        //两把锁，如果两个线程先分别调用了两把锁，再互相调用对方的锁就会产生死锁
        Thread t1 = new Thread(() -> {
            synchronized (A) {
                System.out.println("t1 start");
                synchronized(B){
                    System.out.println("t1 end");
                }
            }
        });

        Thread t2 = new Thread(() -> {
            synchronized (B){
                System.out.println("t2 start");
                synchronized (A){
                    System.out.println("t2 end");
                }
            }
        });

        t1.start();
        t2.start();

    }
}
